package com.wangsong.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wangsong.system.dao.ProductMapper;
import com.wangsong.system.model.Product;
import com.wangsong.system.service.ProductService;
import com.wangsong.system.vo.PageResult;
import com.wangsong.system.vo.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Transactional
    @Override
    public void insertProduct(Product product) {
         productMapper.insertProduct(product);
    }

    @Override
    public void deleteProduct(String[] id) {
    productMapper.deleteProduct(id);
    }

    @Transactional
    @Override
    public int updateProduct(Product product) {
        return productMapper.updateProduct(product);
    }

    @Override
    public Product queryProductById(String id) {
        return productMapper.queryProductById(id);
    }

    @Override
    public PageResult queryProductBySort(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Product> page = productMapper.queryProductBySort(queryPageBean.getName(),queryPageBean.getSort());
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public PageResult queryProductByKeyWord(QueryPageBean queryPageBean) {
        return null;
    }
}
